package com.mlink.ai.chat.ads

import android.app.Activity
import com.adsdk.android.ads.rewarded.OxRewardedAdHelper

val chatRewardCache = ChatRewardAdCache()

class ChatRewardAdCache {

    var mRewardedAdHelper: OxRewardedAdHelper? = null
        private set

    fun initRewardAdCache(activity: Activity) {
        if (mRewardedAdHelper == null) {
            mRewardedAdHelper =
                OxRewardedAdHelper.createAd(activity, AdUtils.getChatRvAdConfig(activity).adId)
            mRewardedAdHelper?.setReloadAfterFailed(true)
        }
        mRewardedAdHelper?.loadAd(AdUtils.getChatRvAdConfig(activity).adPlacement)
    }

    fun initRewardAdHelper(activity: Activity) {
        if (mRewardedAdHelper == null) {
            mRewardedAdHelper =
                OxRewardedAdHelper.createAd(activity, AdUtils.getChatRvAdConfig(activity).adId)
            mRewardedAdHelper?.setReloadAfterFailed(true)
        }
    }

    fun destroyAd() {
        mRewardedAdHelper?.destroyAd()
        mRewardedAdHelper = null
    }

}